package com.zmx.user.web;

import com.zmx.common.common.web.AbstractController;
import com.zmx.common.common.web.rest.ResponseResult;
import com.zmx.user.dto.MemberBlacklistDto;
import com.zmx.user.entity.MemberBlacklist;
import com.zmx.user.service.MemberBlacklistService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 用户黑名单控制器
 * @ClassName: MemberBlacklistController
 * @Author zhaomxr
 * @Date 2022-01-13 15:55
 */
@Api("用户黑名单")
@Slf4j
@RestController
@RequestMapping("memberBlacklist")
public class MemberBlacklistController extends AbstractController<MemberBlacklistDto, MemberBlacklistService> {

    @Autowired
    private MemberBlacklistService memberBlacklistService;

    @ApiOperation(value = "获取用户黑名单", tags = "获取用户黑名单")
    @GetMapping
    public Map<String, Object> getBlacklist(@RequestParam(required = false) Long memberId,
                                            @RequestParam(required = false) String ip) {
        Map<String, Object> result = new HashMap<String, Object>(3);
        try {
            MemberBlacklist memberBlacklist = memberBlacklistService.getBlacklist(memberId, ip);
            result.put("code", 200);
            result.put("msg", "");
            result.put("data", memberBlacklist);
        } catch (Exception e) {
            log.error("获取用户黑名单失败 ", e);
            result.put("code", 201);
            result.put("msg", "获取用户黑名单失败");
            result.put("data", null);
        }
        return result;
    }
}
